package ar.uba.dc.tl.mylanga.interpreter;

import ar.uba.dc.tl.mylanga.analysis.AnalysisAdapter;
import ar.uba.dc.tl.mylanga.node.AAssignmentStatement;
import ar.uba.dc.tl.mylanga.node.ACompoundStatement;
import ar.uba.dc.tl.mylanga.node.PStatement;

import java.util.HashSet;
import java.util.Set;

public class FunctionLocalsCounterAdapter extends AnalysisAdapter {

	private Set<String> locals;

	public FunctionLocalsCounterAdapter() {
		this.locals = new HashSet<>();
	}

	public int getLocalsCount() {
		return this.locals.size();
	}

	@Override
	public void caseACompoundStatement(ACompoundStatement node) {
		for (PStatement statement : node.getStatements()) {
			statement.apply(this);
		}
	}

	@Override
	public void caseAAssignmentStatement(AAssignmentStatement node) {
		this.locals.add(node.getLeftValue().getText());
	}
}
